package com.py.credit.clean.code;

import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.util.CollectionUtils;
import org.springframework.web.context.ContextLoader;
import org.springframework.web.context.WebApplicationContext;

import com.py.credit.dao.RuleCheckingDao;

/**
 * 主体信息重复校验
 * @author Administrator
 *
 */
public class ZtxxRepeatCheck {
	WebApplicationContext context = ContextLoader.getCurrentWebApplicationContext();
	private RuleCheckingDao ruleCheckingDao = context.getBean(RuleCheckingDao.class);
	
	public  boolean run(Map<String, Object> map, String extend) {
		if(String.valueOf(map.get("rootId")).equals("100000")) {
    		if(StringUtils.isNotBlank(String.valueOf(map.get("A000002")))) {
    			Map<String,String> A000002data = ruleCheckingDao.CheckType("t_100000460009_JnuqJ847ju","A000002",String.valueOf(map.get("A000002")));
      	      if(!CollectionUtils.isEmpty(A000002data)) {
      	    	  if (String.valueOf(map.get("A000001")).equals(A000002data.get("A000001"))||String.valueOf(map.get("A000003")).equals(A000002data.get("A000003"))) {
      	    		  return false;
      	    	  } 
      	      }else {
      	    	  return true;
      	      }
    			
    		}else {
    			Map<String,String> A000001data = ruleCheckingDao.CheckType("t_100000460009_JnuqJ847ju","A000001",String.valueOf(map.get("A000001")));
    			  if(!CollectionUtils.isEmpty(A000001data)) {
    				  if (String.valueOf(map.get("A000003")).equals(A000001data.get("A000003"))) {
    					  return false;
    				  }	
    			  }else {
    				  return true;
    			  }
    		}
    		return true;
    	}else if(String.valueOf(map.get("rootId")).equals("100001")) {
    		//根据B000003获取主体信息
			Map<String,String> zrrdata = ruleCheckingDao.CheckType("t_10000190010_UNJNiQhGny","B000003",String.valueOf(map.get("B000003")));
			//判断主体信息是否匹配
			if(!CollectionUtils.isEmpty(zrrdata)) {
				if(String.valueOf(map.get("B000001")).equals(zrrdata.get("B000001"))) {
					return false;
				}
			}else {
				return true;
			}
    	}
    	else if(String.valueOf(map.get("rootId")).equals("100002")) {
    		//根据C000002获取主体信息
			Map<String,String> ffrdata = ruleCheckingDao.CheckType("t_1000020010028_DEfBZD5dof","C000002",String.valueOf(map.get("C000002")));
			//判断主体信息是否匹配
			if(!CollectionUtils.isEmpty(ffrdata)) {
				if(String.valueOf(map.get("C000001")).equals(ffrdata.get("C000001"))) {
					return false;
				}else if(String.valueOf(map.get("C000003"))!=null&&!String.valueOf(map.get("C000003")).equals("")){
					if(String.valueOf(map.get("C000003")).equals(ffrdata.get("C000003"))) {
						return false;
					}				
				}
    	}else {
    		return true;
    	}
	}
	return false;
}
}

